package com.wangjiyuan.giftshuo.ui.fragment.classify.shop.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.classifybean.shop.TreeBean;
import com.wangjiyuan.giftshuo.config.classify.ConstantLength;
import com.wangjiyuan.giftshuo.utils.RecyclerViewAdapterHelper;

import java.util.List;

/**
 * 单品右边的RecyclerView
 * Created by QXL on 2016/11/18.
 */

public class ShopContentRecyclerViewAdapter extends RecyclerViewAdapterHelper<TreeBean.DataBean.CategoriesBean>{
    public ShopContentRecyclerViewAdapter(Context context, List<TreeBean.DataBean.CategoriesBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_shop_content, parent, false);
        return new ViewHolderContent(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        TreeBean.DataBean.CategoriesBean categoriesBean = mList.get(position);
//        数据源
        List<TreeBean.DataBean.CategoriesBean.SubcategoriesBean> subcategories = categoriesBean.getSubcategories();
        String title = categoriesBean.getName();
//      第一个不显示
        if(position==0){
            ((ViewHolderContent)holder).relativeLayout_item_shop_title.setVisibility(View.GONE);
        }
        else {
            ((ViewHolderContent)holder).relativeLayout_item_shop_title.setVisibility(View.VISIBLE);
        }
        ((ViewHolderContent)holder).textView_shop_item_title.setText(title);

        GridLayoutManager gridLayoutManager=new GridLayoutManager(mContext,3, OrientationHelper.VERTICAL,false);
        ShopContentItemRecAdapter recAdapter=new ShopContentItemRecAdapter(mContext,subcategories);
        ((ViewHolderContent) holder).recyclerView_item_shop_content.setHasFixedSize(true);
        ((ViewHolderContent) holder).recyclerView_item_shop_content.setLayoutManager(gridLayoutManager);
        ((ViewHolderContent) holder).recyclerView_item_shop_content.setAdapter(recAdapter);

    }

    class ViewHolderContent extends RecyclerView.ViewHolder {
        RelativeLayout relativeLayout_item_shop_title;
        View title_line;
        TextView textView_shop_item_title;
        RecyclerView recyclerView_item_shop_content;
        public ViewHolderContent(View itemView) {
            super(itemView);
            relativeLayout_item_shop_title= (RelativeLayout) itemView.findViewById(R.id.relativeLayout_item_shop_title);
            LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
                    new GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            params.setMargins(ConstantLength.RELATIVELAYOUT_PADDING_WIDTH, ConstantLength.RELATIVELAYOUT_PADDING_TOP,
                    ConstantLength.RELATIVELAYOUT_PADDING_WIDTH, ConstantLength.RELATIVELAYOUT_PADDING_BOTTOM);
            relativeLayout_item_shop_title.setLayoutParams(params);

            title_line=itemView.findViewById(R.id.title_line);

            textView_shop_item_title= (TextView) itemView.findViewById(R.id.textView_shop_item_title);
            textView_shop_item_title.setPadding(ConstantLength.TITLE_LINE_PADDING_WIDTH,0,
                    ConstantLength.TITLE_LINE_PADDING_WIDTH,0);

            recyclerView_item_shop_content= (RecyclerView) itemView.findViewById(R.id.recyclerView_item_shop_content);
            recyclerView_item_shop_content.setPadding(0, ConstantLength.PADDING_HEIGHT,0, ConstantLength.PADDING_HEIGHT);
        }
    }
}
